#ifndef DATABASE_H
#define DATABASE_H

#include <QtSql>

class Database
{
public:
    Database();

    const static int FAILURE = -1;
    const static int SUCCESS = -2;

    friend class DatabaseLock;

protected:
    bool open();
    void close();

    QSqlDatabase db;
};

// Create DatabaseLock object to open connection to database,
// it automatically closes connection when it is destroyed
//
// This is to avoid having to close the database every time
// a function returns since it automatically closes the
// connection when it falls out of scope.
class DatabaseLock
{
public:
    DatabaseLock(Database * database);
    ~DatabaseLock();

private:
    Database *db;
};

#endif // DATABASE_H
